package com.java.dao;

import com.java.dao.impl.baseDao;
import com.java.doMain.user;
import org.junit.Test;

import java.util.List;

/**
 * @Author xyd
 * @Date 2021/12/6 13:57
 * @Version 1.0
 */
public class userDaoImpl extends baseDao implements userDao {
    @Override
    public user queryAdminByUsernameAndPassword(String name, String password) {
        String sql = "select * from user where username=? and password=?";
        return queryForOne(user.class,sql,name,password);
    }

    @Override
    public user selectByUsername(String username) {
        String sql = "select * from user where username=?";
        return queryForOne(user.class,sql,username);
    }


    @Override
    public int register(String username, String password, String sex, String tel, String b1) {
        String sql = "insert into `user`(username,password,sex,tel,b1) values (?,?,?,?,?)";
        return update(sql,username,password,sex,tel,b1);
    }

    @Override
    public List<user> selectAll() {
        String sql = "select * from user ";
        return queryForList(user.class,sql);
    }

    @Override
    public user selectByUserName(String username) {
        String sql = "select * from user where username = ? ";
        return queryForOne(user.class,sql,username);
    }

    @Override
    public int updateUserB2(int userID, String b2) {
        String sql = "update user set b2=? where userid = ?";
        return update(sql,b2,userID);
    }

    @Override
    public int updateMoney(int userID, double balance) {
        String sql = "update user set balance=? where userid = ?";
        return update(sql,balance,userID);
    }

    @Test
    public void te(){
        user john = selectByUsername("john");
        System.out.println(john);
    }
}
